package com.web.controller;

import com.alibaba.fastjson2.JSON;
import com.web.entity.ResponseResult;
import com.web.entity.Student;
import com.web.service.StudentService;
import com.web.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findStudentAll")
public class FindStudentAll extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //设置内容类型
        response.setContentType("application/json;charset=UTF-8");
        //创建业务逻辑层对象
        StudentService studentService = new StudentServiceImpl();
        //查询所有学生信息
        List<Student> students = studentService.findStudentAll();
        ResponseResult result = new ResponseResult(200, "查询所有学生信息成功！", students);
        response.getWriter().write(JSON.toJSONString(result));
    }
}
